<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ProblemWaySearch
 *
 * @author wupeng
 */
class Application_Model_Filter_ProblemWaySearch {
    //put your code here
    
    public $balusc;
    
    public $starttime;
    
    public $endtime;
    
    public $agentid;
    
    public $channelid;
    
    public $statusid;
    
    public $invoice;
    
    public $isinvoice;
    
    public $isAddform;
    
    public $cityid;
    
    public $startweight;
    
    public $endweight;
    
    public $startpayment;
    
    public $endpayment;
    
    public $startmoney;
    
    public $endmoney;

    public function getSearchFileds() {
        $where = array();
        $and = '';
        $or = '';
        if ($this->balusc != '') {
            $balusc = trim($this->balusc);
            $num = strlen($balusc);
            $where["( "] = 1;
            $or = " and ";
            if ($num == 5) {
                $uwhere[' storeno = '] = $balusc;
                $user = Application_Model_User::getDao()->queryOne($uwhere);
                if ($user) {
                    $where[$or . ' userId = '] = $user->id;
                    $or = " or ";
                } else {
                    $where[$or . ' userId = '] = "";
                    $or = " or ";
                }
            } else if ($num == 11) {
                $storeItem = Application_Model_StoreItem::bybarcode($balusc);
                $wayid = "(";
                if ($storeItem) {
                    $wayItem = $storeItem->getStoreIdWay();
                    if ($wayItem) {
                        foreach ($wayItem as $wayval) {
                            $wayid .= $wayval->wayId . ",";
                        }
                    }
                }
                $wayid .= "0)";
                $where[$or . " id in "] = $wayid;
                $or = " or ";
            } else {
                $where[$or . ' billNo = '] = $balusc;
                $or = " or ";
                $where[$or . ' agentNo = '] = $balusc;
                $where[$or . ' logistics = '] = $balusc;
            }
            $where[") and "] = "1=1";
            $and = ' and ';
            $problem = 0;
        }

        if ($this->starttime != '') {
            $where[$and . 'datePaid >='] = $this->starttime . " 00:00:00";
            $and = ' and ';
        }
        if ($this->endtime != '') {
            $where[$and . 'datePaid <='] = $this->endtime . " 23:59:59";
            $and = ' and ';
        }

        if ($this->agentid != '') {
            $where[$and . ' agentId = '] = $this->agentid;
            $and = ' and ';
        }
        if ($this->channelid != '') {
            $where[$and . ' expressId = '] = $this->channelid;
            $and = ' and ';
        }
        if (!is_null($this->statusid) && $this->statusid != "") {
            $where[$and . " interior = "] = $this->statusid;
            $and = " and ";
        }

        if ($this->invoice != 0) {
            $where[$and . ' isInvoice = '] = 0;
            $and = ' and ';
        }
        if ($this->isinvoice != 0) {
            $where[$and . ' isInvoice = '] = 0;
            $and = ' and ';
            $where[$and . " interior < "] = Application_Model_wayBillItem::Interior_Outstorage;
            $where[$and . " interior != "] = Application_Model_wayBillItem::Interior_Cancel;
        }
        if ($this->isAddform != 0) {
            $where[$and . ' isAddform = '] = 0;
            $and = ' and ';
        }
        if ($this->cityid != null) {
            $where[$and . " state = "] = $this->cityid;
            $and = " and ";
        }
        if ($this->startweight != null && $this->endweight != null) {
            $where[$and . " productWeight >= "] = $this->startweight * 1000;
            $and = " and ";
            $where[$and . " productWeight <= "] = $this->endweight * 1000;
        }
        if ($this->startpayment != null && $this->endpayment != null) {
            $where[$and . " paymentWeight >= "] = $this->startpayment * 1000;
            $and = " and ";
            $where[$and . " paymentWeight <= "] = $this->endpayment * 1000;
        }
        if ($this->startmoney != null && $this->endmoney != null) {

            $where[$and . " shipMoney >= "] = $this->startmoney;
            $and = " and ";
            $where[$and . " shipMoney <= "] = $this->endmoney;
        }
        $where[$and." status = "] = Application_Model_wayBillItem::STATUS_ExpressBack;
        
        
        return $where;
    }
}
